<?php
function messanges(){
    $html="";
    $sql="select * from oders where action='0'";
    $query=select_list($sql);
    if($query){$html.="(".count($query).")";}
    return $html;
}
///////////////////////////////////// phần hiển thi ra sản phẩm
function category_product($query){
$html="";

if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>ID</th>";
		$html.="<th>Product</th>";
		$html.="<th>Author</th>";
		$html.="<th>Price</th>";
		$html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$SalePrice=$row['SalePrice'];
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idBook']."'></td>";
		$html.="<td>".$row['idBook']."</td>";
		$html.="<td>".$row['Name']."</td>";
		$html.="<td>".$row['Author']."</td>";
		$html.="<td>".$SalePrice." đ</td>";
		$html.="<td>".$row['DatePost']."</td>";
		$html.="<td><a href='edit_product.php?id=".$row['idBook']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_product.php?id=".$row['idBook']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
/////////////////////////////////////////////////
function xu_li_hoadon($a,$b,$c){
    $html="";$tr="__";
    //$a=rtim($a,$tr);$b=rtim($b,$tr);$c=rtim($c,$tr);
    $a=explode($tr,$a);$b=explode($tr,$b);$c=explode($tr,$c);
    if(count($a)==count($b) and count($a)==count($c) and count($a)!=0){
        foreach($a as $k=>$v){$price=number_format($c[$k],0,'','.');
            $html.="<div>".$a[$k].": ".$b[$k]." x ".$price." đ</div>";
        }
    }
return $html;
}
//////////////////////////////////////////////////
function bill_customer($a){
$html="";
$sql="select * from book where idcustomer='$a'";
$row=select_one($sql);
if($row){$tongtien=number_format($row['tongtien']*1,0,'','.');
$html.="<div class='clear'><a href='bill.php'><span>Quay lại trang hóa đơn</span></a></div><br class='clear'>";
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Product</th>";
		
		$html.="<th>Total</th>";
		$html.="<th>Action</th>";
		$html.="<th>Date</th>";
      
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";

	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idbill']."'></td>";
		$html.="<td>";
        $html.=xu_li_hoadon($row['name'],$row['quantity'],$row['price']);
        $html.="</td>";
		
		$html.="<td>".$tongtien." đ</td>";
		if($row['action']=='0'){
        $html.="<td>Đặt hàng</td>";
		}
		if($row['action']=='1'){
        $html.="<td>Thanh toán</td>";
		}
		$html.="<td>".$row['datetime']."</td>";
        
		$html.="<td><a href='edit_bill_customer.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_bill.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}else{$html.="<div class='clear'><a href='bill.php'><span>Quay lại trang hóa đơn</span></a></div>";}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";

return $html;
}
//////////////////////////////////////////
function member_bill($a){
$html="";
$sql="select * from member where idmember='$a'";
$row=select_one($sql);
if($row){
$html.="<div class='clear'><a href='member.php'><span>Quay lại trang thành viên</span></a></div><br class='clear'>";
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
		$html.="<th>Email</th>";
		$html.="<th>Phone</th>";
        $html.="<th>Address</th>";
        $html.="<th>Date</th>";
       
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";

	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idmember']."'></td>";
        $html.="<td>".$row['name']."</td>";
		$html.="<td>".$row['email']."</td>";
        $html.="<td>".$row['phone']."</td>";
        $html.="<td>".$row['address']."</td>";
        $html.="<td>".$row['date']."</td>";

		$html.="<td><a href='edit_member.php?id=".$row['idmember']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_member.php?id=".$row['idmember']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";

	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}else{$html.="<div class='clear'><a href='member.php'><span>Quay lại trang thành viên</span></a></div><br class='clear'>";}
return $html;
}
/////////////////////////////////////////////////
function bill_member($a){
$html="";
$sql="select * from bill where idmember='$a'";
$query=select_list($sql);
if($query){
$html.="<div class='clear'><a href='member.php'><span>Quay lại trang hóa đơn</span></a></div><br class='clear'>";

$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Product</th>";
		
		$html.="<th>Total</th>";
		$html.="<th>Action</th>";
		$html.="<th>Date</th>";
        $html.="<th>Member</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){$tongtien=number_format($row['tongtien'],0,'','.');
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idbill']."'></td>";
		$html.="<td>";
        $html.=xu_li_hoadon($row['name'],$row['quantity'],$row['price']);
        $html.="</td>";
		
		$html.="<td>".$tongtien." đ</td>";
		if($row['action']=='1'){
        $html.="<td>Thanh toán</td>";}
		if($row['action']=='0'){
        $html.="<td>Đặt hàng</td>";}
		$html.="<td>".$row['datetime']."</td>";
        $html.="<td><a href='bill_member.php?id=".$a."'><img width='16' height='16' border='0' title='' alt='' src='images/customer.jpg'></a></td>";
		$html.="<td><a href='edit_bill_customer.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_bill.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";}
}else{$html.="<div class='clear'><a href='member.php'><span>Quay lại trang hóa đơn</span></a></div>";}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";

return $html;
}
////////////////////////////////////////////////
function bill($query){
$html="";
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Product</th>";
		
		$html.="<th>Total</th>";
		$html.="<th>Action</th>";
		$html.="<th>Date</th>";
        $html.="<th>Item</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){$tongtien=number_format($row['tongtien'],0,'','.');
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idbill']."'></td>";
		$html.="<td>";
        $html.=xu_li_hoadon($row['name'],$row['quantity'],$row['price']);
        $html.="</td>";
		
		$html.="<td>".$tongtien." đ</td>";
		if($row['action']=='0'){
        $html.="<td>Đặt hàng</td>";
		}
		if($row['action']=='1'){
        $html.="<td>Thanh toán</td>";
		}
		$html.="<td>".$row['datetime']."</td>";
		if($row['idcustomer']!=0){
        $html.="<td><a href='customer_bill.php?id=".$row['idcustomer']."'><img width='16' height='16' border='0' title='' alt='' src='images/customer.jpg'></a></td>";
		$html.="<td><a href='edit_bill_customer.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_bill.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
		}
		if($row['idmember']!=0){
        $html.="<td><a href='member_bill.php?id=".$row['idmember']."'><img width='16' height='16' border='0' title='' alt='' src='images/hoadon.png'></a></td>";
		$html.="<td><a href='edit_bill_member.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_bill.php?id=".$row['idbill']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
		}
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
///////////////////////////////////////////////
function xu_li_oder($a,$b,$c){
    $html="";
    $html.="<div>".$a."</div>";
    $html.="<div>".$b."</div>";
    $html.="<div>".$c."</div>";
return $html;
}
function act_oder($a){
    if($a=='0'){$a="Chưa xem";}
    if($a=='1'){$a="Đã xem";}
    return $a;
}
////////////////////////////////////////////////////
function contact($query){
$html="";
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Title</th>";
		$html.="<th>Content</th>";
		
        $html.="<th>Action</th>";
		$html.="<th>Date</th>";
		$html.="<th>Items</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['id']."'></td>";
        $html.="<td>".$row['title']."</td>";
        $html.="<td>".$row['content']."</td>";
  
       //$html.="<td>".xu_li_oder($row['name'],$row['email'],$row['phone'])."</td>";
        $html.="</td>";
		$action="Chưa xem";
		if($row['action']=='1'){$action="Đã xem";}
        $html.="<td>".$action."</td>";
		$html.="<td>".$row['date']."</td>";
		if($row['idcustomer']!='0' && $row['idmember']=='0'){
		$html.="<td><a href='contact_customer.php?id=".$row['id']."'><img width='16' height='16' border='0' title='' alt='' src='images/hoadon.png'></a></td>";}
		if($row['idcustomer']=='0' && $row['idmember']!='0'){
		$html.="<td><a href='contact_member.php?id=".$row['id']."'><img width='16' height='16' border='0' title='' alt='' src='images/customer.png'></a></td>";}
		$html.="<td><a href='edit_oder.php?id=".$row['id']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_oder.php?id=".$row['id']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}else{$html.="Chưa có phản hồi nào";}
return $html;
}
//////////////////////////////////////////////////
function act_member($a){
    if($a=='1'){$a="active";}
    if($a=='0'){$a="banned";}
    return $a;
}
function member($query){
$html="";
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
		$html.="<th>Email</th>";
		$html.="<th>Phone</th>";
     
        $html.="<th>Active</th>";
		$html.="<th>Date</th>";
		$html.="<th>Bill</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
	foreach($query as $row){
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idUser']."'></td>";
       $html.="<td>".$row['user']."</td>";
       $html.="<td>".$row['Email']."</td>";
       $html.="<td>".$row['Phone']."</td>";
        
        //$html.="<td>".act_member($row['active'])."</td>";
		$html.="<td>".$row['Datime']."</td>";
        //$html.="<td><a href='bill_member.php?id=".$row['idmember']."'><img width='16' height='16' border='0' title='' alt='' src='images/customer.png'></a></td>";
		$html.="<td><a href='edit_member.php?id=".$row['idUser']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_member.php?id=".$row['idUser']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
	}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
////////////////////////////////////////////////
function customer_bill($a){
$html="";
$sql="select * from customer where idcustomer='$a'";
$row=select_one($sql);
if($row){
$html.="<div class='clear'><a href='customer.php'><span>Quay lại trang khách hàng</span></a></div><br class='clear'>";
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
		$html.="<th>Phone</th>";
        $html.="<th>Address</th>";
        $html.="<th>Date</th>";
       
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";

	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idcustomer']."'></td>";
        $html.="<td>".$row['name']."</td>";
        $html.="<td>".$row['phone']."</td>";
        $html.="<td>".$row['address']."</td>";
        $html.="<td>".$row['date']."</td>";

		$html.="<td><a href='edit_customer.php?id=".$row['idcustomer']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_customer.php?id=".$row['idcustomer']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";

	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}else{$html.="<div class='clear'><a href='customer.php'><span>Quay lại trang khách hàng</span></a></div><br class='clear'>";}
return $html;
}
/////////////////////////////////////////////////
function customer($query){
$html="";
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
		$html.="<th>Phone</th>";
        $html.="<th>Address</th>";
        $html.="<th>Date</th>";
        $html.="<th>Bill</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['idcustomer']."'></td>";
        $html.="<td>".$row['name']."</td>";
        $html.="<td>".$row['phone']."</td>";
        $html.="<td>".$row['address']."</td>";
        $html.="<td>".$row['date']."</td>";
        $html.="<td><a href='bill_customer.php?id=".$row['idcustomer']."'><img width='16' height='16' border='0' title='' alt='' src='images/hoadon.png'></a></td>";
		$html.="<td><a href='edit_customer.php?id=".$row['idcustomer']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_customer.php?id=".$row['idcustomer']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
/////////////////////////////////////////////////
function group_pd(){
$html="";
$sql="select * from group_product";
$query=select_list($sql);
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
        $html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['gid']."'></td>";
        $html.="<td>".$row['gname']."</td>";
        $html.="<td>".$row['date']."</td>";
        $html.="<td><a href='edit_gid.php?id=".$row['gid']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_gid.php?id=".$row['gid']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
/////////////////////////////////////////////////
function gname($a){
    $html="";
    $sql="select * from group_product where gid='$a'";
    $query=select_one($sql);
    $html.=$query['gname'];
    return $html;
}
function category_pd(){
$html="";
$sql="select * from category_product";
$query=select_list($sql);
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
		$html.="<th>Group</th>";
        $html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['cid']."'></td>";
        $html.="<td>".$row['cname']."</td>";
        $html.="<td>".gname($row['gid'])."</td>";
        $html.="<td>".$row['date']."</td>";
       $html.="<td><a href='edit_cid.php?id=".$row['cid']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='category_show.php?id=".$row['cid']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
/////////////////////////////////////////////////
function cname($a){
    $html="";
    $sql="select * from category_product where cid='$a'";
    $query=select_one($sql);
    $html.=$query['cname'];
    return $html;
}
function type_pd(){
$html="";
$sql="select * from type_product";
$query=select_list($sql);
if($query){
$html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Name</th>";
		$html.="<th>Category</th>";
        $html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['tid']."'></td>";
        $html.="<td>".$row['tname']."</td>";
        $html.="<td>".cname($row['cid'])."</td>";
        $html.="<td>".$row['date']."</td>";
        $html.="<td><a href='edit_tid.php?id=".$row['tid']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del_tid.php?id=".$row['tid']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
}
//////////////////////////////////////////////////
function tlist($tid){
    $html="";
    $sql="select * from products where tid='$tid'";
    $query=select_list($sql);
    if($query){
        foreach($query as $row){
        	$html.="<tr class='list'>";
        		$price=number_format($row['price'],0,'','.');
        		$html.="<td><input type='checkbox' name='chon[]' value='".$row['id']."'></td>";
        		$html.="<td>".$row['name']."</td>";
        		$html.="<td>details</td>";
        		$html.="<td>".$price." đ</td>";
        		$html.="<td>".$row['date']."</td>";
        		$html.="<td><a href='edit_product.php?id=".$row['id']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
        		$html.="<td><a class='ask' href='del.php?id=".$row['id']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
        	$html.="</tr>";
         }
    }
return $html;
}
function clist($cid){
    $html="";
    $sql="select * from type_product where cid='$cid'";
    $query=select_list($sql);
    if($query){
        foreach($query as $row){
            $html.=tlist($row['tid']);
         }
    }
return $html;
}
///////////////////////////////////////////////////////////////////
function glist($gid){
    $html="";
    $sql="select * from group_product where gid='$gid'";
    $query=select_list($sql);
    if($query){
        foreach($query as $row){
            $html.=clist($row['cid']);
         }
    }
return $html;
}
////////////////////////////////////////////////////////////
function tcategory_product($tid){
    $html="";
    $sql="select * from products where tid='$tid'";
    $query=select_list($sql);
    if($query){
        $html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Product</th>";
		$html.="<th>Detail</th>";
		$html.="<th>Price</th>";
		$html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
foreach($query as $row){
	$html.="<tr class='list'>";
		$price=number_format($row['price'],0,'','.');
		$html.="<td><input type='checkbox' name='chon[]' value='".$row['id']."'></td>";
		$html.="<td>".$row['name']."</td>";
		$html.="<td>details</td>";
		$html.="<td>".$price." đ</td>";
		$html.="<td>".$row['date']."</td>";
		$html.="<td><a href='edit_product.php?id=".$row['id']."'><img border='0' title='' alt='' src='images/user_edit.png'></a></td>";
		$html.="<td><a class='ask' href='del.php?id=".$row['id']."'><img border='0' title='' alt='' src='images/trash.png'></a></td>";
	$html.="</tr>";
}
	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
	$html.="</tr>";
$html.="</table>";
}
return $html;
} 
/////////////////////////////////////////////////////////////////
function ccategory_product($cid){
    $html="";
    $sql="select * from type_product where cid='$cid'";
    $query=select_list($sql);
    if($query){
        $html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Product</th>";
		$html.="<th>Detail</th>";
		$html.="<th>Price</th>";
		$html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
        foreach($query as $row){
            $html.=tlist($row['tid']);
        }
    	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
        $html.="</tr>";
    $html.="</table>";      
}
return $html;
}
///////////////////////////////////////////////////////////////
function gcategory_product($gid){
    $html="";
    $sql="select * from category_product where gid='$gid'";
    $query=select_list($sql);
    if($query){
        $html.="<table>";
	$html.="<tr class='title'>";
		$html.="<th class='rounded'></th>";
		$html.="<th>Product</th>";
		$html.="<th>Detail</th>";
		$html.="<th>Price</th>";
		$html.="<th>Date</th>";
		$html.="<th>Edit</th>";
		$html.="<th>Delete</th>";
	$html.="</tr>";
        foreach($query as $row){
            $html.=clist($row['cid']);
        }
    	$html.="<tr class='ft'>";
		$html.="<td colspan='6'><em></em></td>";
		$html.="<td class='right'></td>";
        $html.="</tr>";
    $html.="</table>";      
}
return $html;
}
///////////////////////////////////////////////////////////////
function tCategories($cid){
$html="";
$sql="select * from type_product where cid='$cid'";
$query=select_list($sql);
if($query){
$html.="<ul>";
foreach($query as $row){
	$html.="<li>";
		$html.="<a";
        if(isset($_REQUEST['tid'])){
            if($row['tid']==$_REQUEST['tid']){
                $html.=" class='current'";
            }
        }
        $html.=" href='tproduct.php?tid=".$row['tid']."'>";
			$html.=$row['tname'];
		$html.="</a>";
	$html.="</li>";
}
$html.="</ul>";
}
return $html;
}
/////////////////////////////////////////////////////////
function cCategories($gid){
$html="";
$sql="select * from category_product where gid='$gid'";
$query=select_list($sql);
if($query){
$html.="<ul>";
foreach($query as $row){$cid=$row['cid'];
	$html.="<li>";
		$html.="<a";
        if(isset($_REQUEST['cid'])){
            if($cid==$_REQUEST['cid']){
                $html.=" class='current'";
            }
        }
        $html.=" href='cproduct.php?cid=".$row['cid']."'>";
			$html.=$row['cname'];
		$html.="</a>";
		$html.=tCategories($cid);
	$html.="</li>";
}
$html.="</ul>";
}
return $html;
}
/////////////////////////////////////////////////////////
function gCategories(){
$html="";
$sql="select * from group_product";
$query=select_list($sql);
if($query){
$html.="<ul>";
foreach($query as $row){$gid=$row['gid'];
	$html.="<li>";
		$html.="<a";
        if(isset($_REQUEST['gid'])){
            $id=$_REQUEST['gid'];
            if($gid==$id){
                $html.=" class='current'";
            }
        }
        $html.=" href='gproduct.php?gid=".$row['gid']."'>";
			$html.=$row['gname'];
		$html.="</a>";
		$html.=cCategories($gid);
	$html.="</li>";
}
$html.="</ul>";
}
return $html;
}
/////////////////////////////////////////////////////////
function glist_option(){
    $html="";
    $sql="select * from category_book where Menu_con =0	and Menu !='menu'";
    $query=select_list($sql);
    if($query){
        $html.="<option value='default'>Chọn dòng sản phẩm</option>";
        foreach($query as $row){
            $html.="<option value='".$row['idCategory']."'>-- ".$row['NameCategory']." --</option>";
        }
    }
return $html;
}
function glist_select_option($id){
    $html="";
    $sql="select * from group_product where gid='$id'";
    $query=select_one($sql);
    $html.="<option value='".$query['gid']."'>--".$query['gname']."--</option>";
    return $html;
}
function clist_select_option($id,$a){
    $html="";
    $sql="select * from category_product where cid='$id' and gid='$a'";
    $query=select_one($sql);
    $html.="<option value='".$query['cid']."'>--".$query['cname']."--</option>";
    $sql="select * from category_product where cid<>'$id' and gid='$a'";
    $query=select_list($sql);
    if($query){foreach($query as $row){
        $html.="<option value='".$row['cid']."'>--".$row['cname']."--</option>";
    }}
    return $html;
}
function tlist_select_option($id,$cid){
     $html="";
    $sql="select * from category_product where gid='$id'";
    $query=select_list($sql);
    if($query){
        $html.="<option value='default'>--Chọn loại sản phẩm--</option>";
        foreach($query as $row){
            $html.="<option value='".$row['cid']."'";
            if($row['cid']==$cid){$html.="  selected='selected'"; }
            $html.=">-- ".$row['cname']." --</option>";
        }
    }
return $html;
}
function prolist_select_option($a,$b){
    $html="";
    $sql="select * from type_product where tid='$a' and cid='$b'";
    $query=select_one($sql);
    $html.="<option value='".$query['tid']."'>--".$query['tname']."--</option>";
    $sql="select * from type_product where tid<>'$a' and cid='$b'";
    $query=select_list($sql);
    if($query){foreach($query  as $row){
        $html.="<option value='".$row['tid']."'>--".$row['tname']."--</option>";
    }}
    return $html;
}
///////////////////////////////////////////////////////////////////////////////
function clist_option($gid){
    $html="";
    $sql="select * from category_product where gid='$gid'";
    $query=select_list($sql);
    if($query){
        $html.="<option value='default'>Chọn loại sản phẩm</option>";
        foreach($query as $row){
            $html.="<option value='".$row['cid']."'>-- ".$row['cname']." --</option>";
        }
    }
return $html;
}
////////////////////////////////////////////////////////////////////////////
function tlist_option($cid){
    $html="";
    $sql="select * from type_product where cid='$cid'";
    $query=select_list($sql);
    if($query){
        $html.="<option value='default'>Chọn dòng sản phẩm</option>";
        foreach($query as $row){
            $html.="<option value='".$row['tid']."'>-- ".$row['tname']." --</option>";
        }
    }
return $html;
}
///////////////////////////////////////////////////////////////////////////////////////
?>